package tv.youxing.android.ui;
/**
 * Created by apple on 2017/4/24.
 */

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import tv.youxing.android.Interface.CustomToobarImp;
import tv.youxing.android.R;
import tv.youxing.android.custom.CustomToolbar;
import tv.youxing.android.fragment.PhoneLoginFragment;
import tv.youxing.android.fragment.UserPwdLoginFragment;
import tv.youxing.android.utils.StaticClass;


/**
 * 项目名：   youxing
 * 包名：     tv.youxing.android .ui
 * 文件名：   LoginActivity
 * 创建者：   叶克武
 * 创建时间： 2017/4/24 下午2:08
 * 描述：    TODO
 */
public class LoginActivity extends BaseActivity {

    private TextView tvRegister;

    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private List<String> mTitle;
    private List<Fragment> mFragment;
    TextView userAgreement;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initData();
        initView();
    }


    private void initData(){
        mTitle = new ArrayList<>();
        mTitle.add("账号密码登录");
        mTitle.add("快捷免密登录");

        mFragment = new ArrayList<>();
        mFragment.add(new UserPwdLoginFragment());
        mFragment.add(new PhoneLoginFragment());
    }


    private void initView() {

        tvRegister = (TextView) findViewById(R.id.tv_register);
        tvRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
            }
        });


        userAgreement = (TextView) findViewById(R.id.userAgreement);
        userAgreement.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(LoginActivity.this, AdvertisementWEBActivity.class);
                intent.putExtra("url", StaticClass.registerAgreement);
                intent.putExtra("title","用户协议");
                startActivity(intent);
            }
        });


        CustomToolbar customToolbar = (CustomToolbar) findViewById(R.id.tb);
        customToolbar.setBackClickLister(new CustomToobarImp.back() {
            @Override
            public void onclick() {
                finish();
            }
        });
        customToolbar.setRightTextClickLister(new CustomToobarImp.right_text() {
            @Override
            public void onclick() {
                startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
            }
        });

        mTabLayout = (TabLayout) findViewById(R.id.mTabLayout);
        mViewPager = (ViewPager) findViewById(R.id.mViewPager);


        mViewPager.setOffscreenPageLimit(mFragment.size());

        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                switch (position){
                    case 0:

                        break;
                    case 1:

                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

            @Override
            public Fragment getItem(int position) {
                return mFragment.get(position);
            }

            @Override
            public int getCount() {
                return mFragment.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mTitle.get(position);
            }

        });

        mTabLayout.setupWithViewPager(mViewPager);

    }





}
